/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package com.googlecode.ivybeans.module.lookup;

import com.googlecode.ivybeans.module.ProjectConfigurationHelper;
import com.googlecode.ivybeans.module.IvyLibraryController;
import com.googlecode.ivybeans.module.ProjectOpenedHookImpl;
import com.googlecode.ivybeans.module.classpath.ClassPathProviderImpl;

import com.googlecode.ivybeans.module.queries.JavadocForBinaryQueryImpl;
import java.io.File;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectInformation;
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation;
import org.netbeans.spi.project.AuxiliaryConfiguration;
import org.netbeans.spi.project.LookupProvider;
import org.netbeans.spi.project.ui.ProjectOpenedHook;
import org.openide.modules.InstalledFileLocator;
import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;

/**
 * 
 * @author lforet
 */
public class LookupProviderImpl implements LookupProvider {

    public Lookup createAdditionalLookup(Lookup baseLookup) {
        AuxiliaryConfiguration auxiliaryConfiguration = baseLookup.lookup(AuxiliaryConfiguration.class);
        Project project = baseLookup.lookup(Project.class);
        assert auxiliaryConfiguration != null;
        assert project != null;
        IvyLibraryController ivyLibraryController = ProjectConfigurationHelper.getInstance().initController(project, auxiliaryConfiguration);
        assert ivyLibraryController != null;

        ClassPathProviderImpl ivyCPProvider = new ClassPathProviderImpl(project);
        ProjectOpenedHook ivyProjectOpenedHook = new ProjectOpenedHookImpl(project, ivyCPProvider);

        File ivyLibFile = InstalledFileLocator.getDefault().locate("modules/ext/ivy-2.0.0.jar", "fr.jayasoft.ivy.ant", false);
        System.setProperty("ivy.home", ivyLibFile.getParentFile().getAbsolutePath());

        File antContribFile = InstalledFileLocator.getDefault().locate("modules/ext/ant-contrib-1.0b3.jar", "net.sf.antcontrib", false);
        System.setProperty("ant-contrib.lib", antContribFile.getAbsolutePath());
        
        JavadocForBinaryQueryImplementation jfbq = new JavadocForBinaryQueryImpl(ivyLibraryController);
//         return Lookups.fixed(new Object[]{
//             ivyLibraryController.getIvyLibrary(),
//             ivyCPProvider,
//             ivyLibraryController,
//             ivyProjectOpenedHook});
return Lookups.fixed(new Object[]{
                    ivyLibraryController.getIvyLibrary(),
                    ivyCPProvider,
                    ivyLibraryController,
                    ivyProjectOpenedHook,
                    jfbq
                });

    }
}
